import { generateQuestionsAI } from "../text/ai.js";

export const generateQuestions = async (ctx) => {
  try {
    const { type, count, language } = ctx.request.body;

    // 简单的参数验证
    if (!type || !count) {
      ctx.status = 400;
      ctx.body = {
        code: 1,
        message: "缺少必要的参数: type 或 count",
        data: null
      };
      return;
    }

    const result = await generateQuestionsAI(type, count, language);

    ctx.body = result;

  } catch (err) {
    console.error('Error in generateQuestions controller:', err);
    ctx.status = 500;
    ctx.body = {
      code: 1,
      message: err.message || "生成题目失败",
      data: null
    };
  }
}; 